import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

let initState = {
    tokenInfo: {},
    userInfo: {
        name: "kky",
    },
};
const allStateObj = JSON.parse(localStorage.getItem("state"));
if (allStateObj) {
    initState = allStateObj;
}
export default new Vuex.Store({
    state: initState,
    mutations: {
        saveTokenInfo(state, token) {
            state.tokenInfo = token;
            this.commit("saveStatetoStorage");
        },
        saveStatetoStorage(state) {
            localStorage.setItem("state", JSON.stringify(state));
        },
    },
    actions: {},
    modules: {},
});